package cheme.ProcessEditor.Table;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Insets;

import cheme.ProcessEditor.Figures.AbstractResizableGroupFig;
import cheme.ProcessEditor.Parts.Streams.Tag.IDecoratorFigure;

public class SubTableFig extends AbstractResizableGroupFig implements ISubTable
{
	static Insets insets = new Insets(0);
	
	public SubTableFig()
	{	
		super();
		
		SubTableLayout layout = new SubTableLayout(null);
		setLayoutManager(layout);
	}
	
	@Override
	public SubTableLayout getLayoutManager()
	{
		return (SubTableLayout)super.getLayoutManager();
	}
	
	@Override
	public void add(IFigure figure, Object constraint, int index)
	{
		/*
		 * Give the newly added item its own layout
		 */
		IFigure unwrapped = figure;
		
		while(unwrapped instanceof IDecoratorFigure)
		{
			unwrapped = ((IDecoratorFigure)unwrapped).getContentPane();
		}
		
		getLayoutManager().add(unwrapped);
		
		super.add(figure, constraint, index);
	}
	
	@Override
	public void remove(IFigure figure)
	{
		IFigure unwrapped = figure;
		
		while(unwrapped instanceof IDecoratorFigure)
		{
			unwrapped = ((IDecoratorFigure)unwrapped).getContentPane();
		}
		
		getLayoutManager().remove(unwrapped);
		
		super.remove(figure);
	}
	
	@Override
	public Insets getInsets()
	{
		return insets;
	}
}
